
import redis,time
def get_heartbeat(name):

    # 连接到远程服务器
    r = redis.Redis(host='www.lrdkzz.com', port=6379, db=0, password='123456')
    # try:
    # print("get ", name)
    import eventlet  # 导入eventlet这个模块
    eventlet.monkey_patch()  # 必须加这条代码
    with eventlet.Timeout(10, False):  # 设置超时时间为2秒
        get_data = r.get(name)
        get_string = str(get_data, "utf-8")
        get_data_c = r.get(name + "_c")
        get_string_c = str(get_data_c, "utf-8")
        print(name, get_string)
        return [float(get_string),get_string_c]

    return [-1,"0.000"]

def get_heartbeat_state():
    res_list = get_heartbeat("6400")
    hb_time = res_list[0]
    # numeracy = res_list[1]
    # hb_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(hb_time))
    cur_time = time.time()
    minute_warm = 10
    if cur_time - hb_time > 60 * minute_warm:
        return False
    else:
        return True

if __name__ == "__main__":
    res = get_heartbeat_state()
    print(res)